const app = getApp();
import number from "../../components/lin-ui/common/async-validator/validator/number.js"
import {
  imageUrl
} from "../../utils/imageutil.js"
import {
  to_tim_chat
} from "../../utils/to_tim_chat"
Page({
  data: {
    imageUrl,
    stepList: [],
    wid: '',
    order_id: '',
    type: '', //2特派订单
    avatar: '', //家政员头像
    level: '', //星级
    user_nickname: '', //a家政员昵称
    workinfo: null,
    markers: [],
    image: [],
    step: '', //订单状态
    state: '', //
    housekeeper_id: '', //家政员ID
    id: '',
    to_uid: '',
    img: [],
    start_image: [],
    aunt: '',
    get_aunt_info: {},
    get_money: '',
    deduction_price: 0, //获取抵扣的金额
    paid_price: '', //实付金额

    is_hy: false, //是否选择购买会员卡
    member_type: 1, //会员
    hy_price: 0, //会员价格
    service_charge: 0, //手续费
    hy_money: 0, //计算会员卡或10%手续费
    hy_list: [],
    is_happiness_integral: false,
    is_integral: false,
    integral: 0, //服务指数
    happiness_integral: 0, //幸福指数
    uer_integral: 0, //抵扣的服务指数
    user_happiness_integral: 0, //抵扣的幸福指数

    uer_integral_num: 0,
    user_happiness_integral_num: 0,

    show_shop_bg: false, //获得消费卷弹窗

    gqm: '', //签名

    show_renewal: false,
    num: '',

    uid: '',

    rechouse_list: [],

    caseCode: "",
    day_type: "",

    is_RenewWork: false,
    paytype_list: [],
    has_jump: false,
    show_code_img: false,

  },
  onLoad: function (options) {
    wx.removeStorageSync('baoxian_info')
    this.setData({
      uid: wx.getStorageSync('userInfo').id
    })
    wx.removeStorageSync('get_aunt_info')
    wx.removeStorageSync('qm_src')

    if (options.wid) {
      this.setData({
        wid: options.wid
      })
      this.getWorkinfo()
      this.get_rechouse_list()
    } else if (options.order_id) {
      this.setData({
        order_id: options.order_id
      })
      this.getOrderInfo()
    }
    this.MembershipList()
    this.GetBasicUserinfo()
  },

  onShow() {

    if (this.data.has_jump && this.data.is_RenewWork) {
      getApp().showModal('是否已完成支付', true).then(() => {
        this.getWorkinfo()
        this.get_rechouse_list()
      })
      this.setData({
        has_jump: false
      })
    } else if (this.data.has_jump && !this.data.is_RenewWork) {
      getApp().showModal('是否已完成支付', true).then(() => {
        setTimeout(() => {
          wx.navigateBack()
        }, 1000)
      })
      this.setData({
        has_jump: false
      })
    } else if (this.data.has_jump) {
      setTimeout(() => {
        wx.navigateBack()
      }, 1000)
    }


    if (wx.getStorageSync('get_aunt_info')) {
      this.setData({
        get_aunt_info: wx.getStorageSync('get_aunt_info')
      })
    }
    if (wx.getStorageSync('qm_src')) {
      this.setData({
        gqm: wx.getStorageSync('qm_src')
      })
    }
    if (wx.getStorageSync('baoxian_info')) {
      this.setData({
        ["workinfo.insure_name"]: wx.getStorageSync('baoxian_info').caseName,
        ["workinfo.insure_money"]: Number(wx.getStorageSync('baoxian_info').monthMoney),
        ["workinfo.insure_remark"]: wx.getStorageSync('baoxian_info').title,
        caseCode: wx.getStorageSync('baoxian_info').caseCode,
        day_type: wx.getStorageSync('baoxian_info').day_type,
      })
      wx.removeStorageSync('baoxian_info')
    }
  },

  get_paytype() {
    return new Promise((a, b) => {
      getApp().globalData.post({
        url: '/api/applet.oyc/paytype.html',
        data: {
          storeid: this.data.workinfo.store_id
        }
      }, true).then(res => {
        if (res.data.code == 1) {
          this.setData({
            paytype_list: res.data.data
          })
          a()
        } else {
          getApp().showModal(res.data.msg)
        }
      })
    })

  },

  close_baoxian() {
    this.setData({
      caseCode: "",
      day_type: "",
      ["workinfo.insure_name"]: "",
      ["workinfo.insure_money"]: 0,
      ["workinfo.insure_remark"]: "",
    })
  },

  get_rechouse_list() {
    getApp().globalData.posts('/api/app/work/sorting/ouyoung_api/rechouse', {
      work_id: this.data.wid
    }).then(res => {
      this.setData({
        rechouse_list: res.data.data.list
      })
    })
  },

  to_aunt(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/aunt/index?uid=' + id + '&type=1'
    })
  },

  change_renewal(e) {
    this.setData({
      num: e.detail.value
    })
  },
  renewal_aunt(e) {
    this.setData({
      renewal_aunt: e.detail.value
    })
  },

  GetDkprice() {
    return new Promise((reslove, reject) => {
      app.globalData.post({
        data: {
          do: 'GetDkprice',
          uid: wx.getStorageSync('userInfo').id,
          price: (Number(this.data.get_money) - Number(this.data.deduction_price)).toFixed(2),
          is_happiness_integral: this.data.is_happiness_integral ? 1 : 2,
          is_integral: this.data.is_integral ? 1 : 2
        }
      }).then(res => {
        this.setData({
          user_integral: res.data.data.integral_price,
          user_happiness_integral: res.data.data.happiness_integral_price,
          user_integral_num: res.data.data.integral,
          user_happiness_integral_num: res.data.data.happiness_integral,
        })
        reslove()
      })
    })
  },

  GetWorkPay() {
    app.globalData.post({
      data: {
        do: 'GetWorkPay',
        release_work_id: this.data.wid
      }
    }).then(res => {
      this.setData({
        deduction_price: res.data.data.price,
      })
    })
  },

  change_show_shop_bg() {
    this.setData({
      show_shop_bg: false
    })
    wx.reLaunch({
      url: '/store/store',
    })
  },

  GetBasicUserinfo() {
    app.globalData.post({
      data: {
        a: 'wxapp2',
        do: 'GetBasicUserinfo',
        uid: wx.getStorageSync('userInfo').id
      }
    }).then(res => {
      this.setData({
        member_type: res.data.data.member_type, // 1 = 会员 0 = 非会员
        integral: res.data.data.integral, //服务指数
        happiness_integral: res.data.data.happiness_integral, //幸福指数
      })
    })
  },

  getWorkinfo() {
    app.globalData.post({
      data: {
        do: 'Workinfo',
        wid: this.data.wid,
      }
    }).then(res => {
      let data = res.data.data;
      this.setData({
        workinfo: data,
        step: data.step,
        state: data.state,
        housekeeper_id: data.housekeeper_id,
        id: data.id,
        to_uid: data.to_uid,
        type: data.type,
        level: data.level,
        avatar: data.avatar,
        user_nickname: data.user_nickname,
        image: data.image,
        start_image: data.start_image,
        markers: [{
          id: 1,
          latitude: data.lat,
          longitude: data.lng,
          title: data.address + data.doorplate,
          iconPath: imageUrl + '/matron/maps.png',
          width: '48rpx',
          height: '48rpx'
        }],
        stepList: [{
          title: '接单匹配中',
          time: data.addtime ? data.addtime : ''
        }, {
          title: '幸福家政已接单',
          time: data.grabtime ? data.grabtime : ''
        }, {
          title: '开始服务',
          time: data.starttime ? data.starttime : ''
        }, {
          title: '结束服务',
          time: data.endtime ? data.endtime : ''
        }, {
          title: '上传凭证',
          time: data.voucher_time ? data.voucher_time : ''
        }]
      })
      if (this.data.workinfo.insure_money) {
        this.setData({
          ['workinfo.insure_money']: Number(this.data.workinfo.insure_money)
        })
      }
      this.GetWorkPay()
    })
  },
  getOrderInfo() {
    app.globalData.post({
      data: {
        do: 'OrderInfo',
        order_id: this.data.order_id,
      }
    }).then(res => {
      let data = res.data;
      this.setData({
        workinfo: data.good[0],
        aunt: data.aunt[0],
        id: data.order.id,
        ['workinfo.uid']: data.order.user_id,
        ['workinfo.store_id']: data.order.store_id,
        ['workinfo.lng']: data.order.lng,
        ['workinfo.lat']: data.order.lat,
        ['workinfo.category']: data.good[0].name,
        ['workinfo.user_name']: data.order.name,
        ['workinfo.tel']: data.order.tel,
        ['workinfo.address']: data.order.address,
        ['workinfo.doorplate']: data.order.doorplate,
        ['workinfo.content']: data.order.note == 'undefined' ? '' : data.order.note,
        ['workinfo.step']: data.order.step,
        ['workinfo.goods_img']: data.good[0].img,
        ['workinfo.work_tc']: true,
        ['workinfo.state']: data.order.status, //状态:0待付款,1已支付,2已抢单,3完成,4删除,5完成评价,6取消订单
        image: data.order.img,
        start_image: data.order.start_image || [],
        markers: [{
          id: 1,
          latitude: data.order.lat,
          longitude: data.order.lng,
          title: data.order.address + data.order.doorplate,
          iconPath: imageUrl + '/matron/maps.png',
          width: '48rpx',
          height: '48rpx'
        }],
        stepList: [{
          title: '接单匹配中',
          time: data.order.pay_time ? data.order.pay_time : ''
        }, {
          title: '幸福家政已接单',
          time: data.order.grabtime ? data.order.grabtime : ''
        }, {
          title: '开始服务',
          time: data.order.starttime ? data.order.starttime : ''
        }, {
          title: '结束服务',
          time: data.order.endtime ? data.order.endtime : ''
        }, {
          title: '上传凭证',
          time: data.order.voucher_time ? data.order.voucher_time : ''
        }]
      })
    })
  },
  btns(e) {
    wx.navigateTo({
      url: './abrogate?wid=' + e.currentTarget.dataset.id + '&type=1',
    })
  },
  to_tim() {
    to_tim_chat(this.data.workinfo.im)
  },
  appraise() { //去评价
    if (this.data.wid) {
      wx.navigateTo({
        url: '../order/appraise?id=' + this.data.id + '&to_uid=' + this.data.to_uid + '&type=1',
      })
    } else {
      wx.navigateTo({
        url: '../order/appraise?id=' + this.data.id + '&to_uid=' + this.data.to_uid,
      })
    }
  },
  change_money(e) {
    let hy_money = 0
    if (this.data.member_type == 1) {
      if (Number(e.detail.value) - Number(this.data.deduction_price) <= 0) {
        wx.showToast({
          title: '实付金额应大于0元',
          icon: 'none'
        })
        this.setData({
          paid_price: ''
        })
        return
      }
    } else {
      if (this.data.is_hy) {
        if (Number(e.detail.value) - Number(this.data.deduction_price) + Number(this.data.hy_price) <= 0) {
          wx.showToast({
            title: '实付金额应大于0元',
            icon: 'none'
          })
          this.setData({
            paid_price: ''
          })
          return
        } else {
          hy_money = Number(this.data.hy_price)
        }
        this.setData({
          hy_money: hy_money
        })
      } else {
        if (Number(e.detail.value) + (Number(e.detail.value) * 0.1) - Number(this.data.deduction_price) <= 0) {
          wx.showToast({
            title: '实付金额应大于0元',
            icon: 'none'
          })
          this.setData({
            paid_price: '',
            service_charge: ''
          })
          return
        } else {
          hy_money = (Number(e.detail.value) * 0.1).toFixed(2)
          this.setData({
            service_charge: (Number(e.detail.value) * 0.1).toFixed(2),
            hy_money: (Number(e.detail.value) * 0.1).toFixed(2),
          })
        }
      }
    }
    this.setData({
      get_money: Number(e.detail.value),
    })
    this.GetDkprice().then(() => {
      // Number(this.data.deduction_price) 订单押金
      this.setData({
        paid_price: Number(((Number(e.detail.value) - Number(this.data.deduction_price) + Number(hy_money)).toFixed(2) - Number(this.data.user_happiness_integral) - Number(this.data.user_integral)).toFixed(2))
      })
    })
  },
  to_get_aunt() {
    wx.navigateTo({
      url: './get_aunt?order_id=' + this.data.id,
    })
  },
  to_gqm() {
    if (this.data.get_aunt_info.id) {
      wx.navigateTo({
        url: '/pages/aunt/handwriting/index?qm=true&id=' + this.data.get_aunt_info.id + '&addr_id=' + this.data.workinfo.area + this.data.workinfo.address + this.data.workinfo.doorplate,
      })
    } else {
      wx.showToast({
        title: '请先选择服务人员',
        icon: 'none'
      })
    }
  },

  RenewalWork() {
    if (Number(this.data.num >= 1)) {
      app.globalData.post({
        data: {
          do: 'RenewalWork',
          a: 'wxapp2',
          order_id: this.data.id,
          num: this.data.num,
        }
      }).then(res => {
        let data = res.data.data
        console.log(data,"1111");
        if (getApp().globalData.appletpayves_info.work == 3) {
          getApp().payPlugin(data.orderNo).then(() => {
            getApp().showModal('支付成功').then(() => {
              this.setData({
                show_renewal: false
              })
            })
          })
          return
        }
        wx.requestPayment({
          nonceStr: data.nonceStr,
          package: data.package,
          paySign: data.paySign,
          timeStamp: data.timeStamp,
          signType: data.signType,
          complete: (s) => {
            if ("requestPayment:ok" == s.errMsg) {
              getApp().showModal('支付成功').then(() => {
                this.setData({
                  show_renewal: false
                })
              })
            }
          }
        })
      })
    } else {
      wx.showToast({
        title: '续费时常需大于等于1小时',
        icon: 'none'
      })
    }
  },
  close_show_renewal() {
    this.setData({
      show_renewal: false
    })
  },
  show_RenewalWork() {
    this.setData({
      show_renewal: true
    })
  },

  to_pay() {
    if (this.data.workinfo.money != 0) {
      this.pay(this.data.id)
    } else {
      if (!this.data.get_aunt_info.uid) {
        wx.showToast({
          title: '请选择服务人员',
          icon: 'none'
        })
        return
      }
      if (!this.data.get_money) {
        wx.showToast({
          title: '请输入实付金额',
          icon: 'none'
        })
        return
      }

      if (!this.data.gqm) {
        wx.showToast({
          title: '请先签名',
          icon: 'none'
        })
        return
      }

      // if (!this.data.caseCode) {
      //   wx.showToast({
      //     title: '请先选择保险方案',
      //     icon: 'none'
      //   })
      //   return
      // }

      let baoxian_obj = {}
      if (this.data.caseCode) {
        baoxian_obj = {
          bx_money: this.data.workinfo.insure_money,
          caseCode: this.data.caseCode,
          day_type: this.data.day_type ? this.data.day_type : 1,
        }
      }

      app.globalData.post({
        data: {
          do: 'ReleaseWorkUpdate',
          id: this.data.id,
          money: this.data.get_money,
          to_uid: this.data.get_aunt_info.id,
          gqm: this.data.gqm,
          ...baoxian_obj
        }
      }).then(res => {
        let data = res.data.data
        if (res.data.status != 1) {
          app.showModal(res.data.msg)
        } else {
          this.pay(data)
        }
      })
    }
  },

  to_pay3() {
    if (!this.data.get_aunt_info.uid) {
      wx.showToast({
        title: '请选择服务人员',
        icon: 'none'
      })
      return
    }
    if (!this.data.gqm) {
      wx.showToast({
        title: '请先签名',
        icon: 'none'
      })
      return
    }
    app.globalData.post({
      data: {
        do: 'ReleaseWorkUpdate',
        id: this.data.id,
        to_uid: this.data.get_aunt_info.id,
        gqm: this.data.gqm
      }
    }).then(res => {
      let data = res.data.data
      app.globalData.post({
        data: {
          do: 'Payv3',
          a: 'wxapp2',
          order_id: data,
          user_id: wx.getStorageSync('userInfo').id,
          openid: wx.getStorageSync('userInfo').openid,
          type: 4,
          gqm: this.data.gqm
        }
      }).then(() => {
        app.showModal('提交成功').then(() => {
          wx.navigateBack({
            delta: 1
          })
        })
      })
    })
  },

  pay(id) { //微信支付
    let _this = this;
    let data = {};
    let happiness_integral_obj = {};
    let integral_obj = {};
    let gqm_obj = {};
    // is_buymember = '';is_buymember 1 = 购买会员卡 2 = 不购买 当 is_buymember = 1时,需要传ship_id(卡号id)
    if (this.data.workinfo.work_type) {
      if (this.data.member_type == 1) {
        // 是会员
        data = {
          is_buymember: 2
        }
      } else {
        if (this.data.is_hy) {
          // 购买会员卡
          data = {
            is_buymember: 1,
            ship_id: this.data.hy_list[0].id
          }
        } else {
          data = {
            is_buymember: 2
          }
        }
      }

      if (this.data.is_happiness_integral) {
        happiness_integral_obj = {
          is_happiness_integral: 1
        }
      } else {
        happiness_integral_obj = {
          is_happiness_integral: 2
        }
      }
      if (this.data.is_integral) {
        integral_obj = {
          is_integral: 1
        }
      } else {
        integral_obj = {
          is_integral: 2
        }
      }
      gqm_obj = {
        gqm: this.data.gqm
      }
    }

    this.get_paytype().then(() => {
      let paytype_list = this.data.paytype_list
      let itemList = []

      paytype_list.forEach((v, i) => {
        itemList.push(v.title)
      })

      wx.showActionSheet({
        itemList,
        success: (sheet) => {
          let tapIndex = sheet.tapIndex
          let paytype = paytype_list[tapIndex].paytype

          let that = this
          if (paytype == 6) {
            wx.setStorageSync('pay_info', {
              do: 'pay',
              order_id: id,
              user_id: wx.getStorageSync('userInfo').id,
              openid: wx.getStorageSync('userInfo').openid,
              type: this.data.wid ? 4 : '',
              ...data,
              ...happiness_integral_obj,
              ...integral_obj,
              ...gqm_obj,
              paytype
            })
            wx.navigateTo({
              url: '/online_bank/list?id=' + id
            })
            return
          }
          app.globalData.post({
            data: {
              do: 'pay',
              order_id: id,
              user_id: wx.getStorageSync('userInfo').id,
              openid: wx.getStorageSync('userInfo').openid,
              type: this.data.wid ? 4 : '',
              ...data,
              ...happiness_integral_obj,
              ...integral_obj,
              ...gqm_obj,
              paytype
            }
          }).then(res => {
            let data = res.data
            if (data.code == 0) {
              getApp().showModal(data.msg)
              return
            }
            if (data.pay_status == 2) {
              wx.showModal({
                title: '提示',
                content: '支付成功',
                showCancel: false,
                success: () => {
                  wx.navigateBack({
                    delta: 1,
                  })
                }
              })
              return
            }
            if (getApp().globalData.appletpayves_info.work == 3) {
              getApp().payPlugin(data.orderNo).then(() => {
                getApp().showModal('支付成功').then(() => {
                  if (that.data.member_type == 1) {
                    that.setData({
                      show_shop_bg: true
                    })
                  } else {
                    setTimeout(() => {
                      wx.navigateBack()
                    }, 1000)
                  }
                })
              })
              return
            }

            if (res.data.jump) {
            
              this.selectComponent('#zfb_pay').get_code(data.jump)
              this.setData({
                show_code_img: true,
                has_jump: true,
                is_RenewWork: false,
              })
              return
            } else {
              this.setData({
                has_jump: false
              })
            }

            if (!data.package) {
              getApp().showModal('暂无法使用该支付方式，请选择其他支付方式', true).then(() => {
                this.pay(id)
              })
              return
            }
            // console.log(data,"走到这来了");
            wx.requestPayment({
              nonceStr: data.nonceStr,
              package: data.package,
              paySign: data.paySign,
              timeStamp: data.timeStamp,
              signType: data.signType,
              complete(s) {
                if ("requestPayment:ok" == s.errMsg) {
                  wx.showToast({
                    title: "支付成功"
                  })
                  if (that.data.member_type == 1) {
                    that.setData({
                      show_shop_bg: true
                    })
                  } else {
                    setTimeout(() => {
                      wx.navigateBack({
                        delta: 1,
                      })
                    }, 1000)
                  }
                }
              }
            })
          })

        }
      })
    })

  },

  has_paytype() {
    return new Promise((a, b) => {
      if (this.data.wid) {

      }
    })
  },


  MembershipList() {
    app.globalData.post({
      data: {
        do: 'MembershipList',
        uid: wx.getStorageSync('userInfo').id
      }
    }).then(res => {
      this.setData({
        hy_list: res.data.result[0].list
      })
    })
  },
  change_hy() {
    if (!this.data.get_money) {
      wx.showToast({
        title: '请先输入家政员薪酬',
        icon: 'none'
      })
      return
    }
    // 选择会员卡
    this.setData({
      is_hy: !this.data.is_hy,
      hy_price: this.data.hy_list[0].price
    })
    let hy_money = 0
    if (this.data.is_hy) {
      if (Number(this.data.get_money) - Number(this.data.deduction_price) + Number(this.data.hy_price) <= 0) {
        wx.showToast({
          title: '实付金额应大于0元',
          icon: 'none'
        })
        this.setData({
          paid_price: ''
        })
        return
      } else {
        hy_money = Number(this.data.hy_price)
      }
    } else {
      if (Number(this.data.get_money) + (Number(this.data.get_money) * 0.1) - Number(this.data.deduction_price) <= 0) {
        wx.showToast({
          title: '实付金额应大于0元',
          icon: 'none'
        })
        this.setData({
          paid_price: '',
          service_charge: ''
        })
        return
      } else {
        hy_money = (Number(this.data.get_money) * 0.1).toFixed(2)
        this.setData({
          service_charge: (Number(this.data.get_money) * 0.1).toFixed(2)
        })
      }
    }
   
    this.setData({
      // Number(this.data.deduction_price) 订单押金
      hy_money: hy_money, //计算会员卡或10%手续费
      paid_price: ((Number(this.data.get_money) - Number(this.data.deduction_price) + Number(hy_money)).toFixed(2) - Number(this.data.user_happiness_integral) - Number(this.data.user_integral)).toFixed(2)
    })
  },

  change_happiness_integral() {
    // 幸福指数
    if (!this.data.get_money) {
      wx.showToast({
        title: '请先输入家政员薪酬',
        icon: 'none'
      })
      return
    }
    this.setData({
      is_happiness_integral: !this.data.is_happiness_integral,
    })
    // let user_happiness_integral = 0,get_money=this.data.get_money,happiness_integral = this.data.happiness_integral;
    // if(happiness_integral>=get_money*0.2){
    //   user_happiness_integral = (get_money*0.2).toFixed(2)
    // }else{
    //   user_happiness_integral = happiness_integral
    // }
    // if(this.data.is_happiness_integral){
    //   this.setData({
    //     user_happiness_integral:user_happiness_integral
    //   })
    // }else{
    //   this.setData({
    //     user_happiness_integral:0
    //   })
    // }
    this.GetDkprice().then(() => {
      // Number(this.data.deduction_price) 订单押金
      this.setData({
        paid_price: Number(((Number(this.data.get_money) - Number(this.data.deduction_price) + Number(this.data.hy_money)).toFixed(2) - Number(this.data.user_happiness_integral) - Number(this.data.user_integral)).toFixed(2))
      })
    })
  },
  change_integral() {
    // 服务指数
    if (!this.data.get_money) {
      wx.showToast({
        title: '请先输入家政员薪酬',
        icon: 'none'
      })
      return
    }
    this.setData({
      is_integral: !this.data.is_integral,
    })
    // let user_integral = 0,get_money=this.data.get_money,integral = this.data.integral;
    // if(integral>=get_money*0.2){
    //   user_integral = (get_money*0.2).toFixed(2)
    // }else{
    //   user_integral = integral
    // }
    // if(this.data.is_integral){
    //   this.setData({
    //     user_integral:user_integral
    //   })
    // }else{
    //   this.setData({
    //     user_integral:0
    //   })
    // }
    this.GetDkprice().then(() => {
      // Number(this.data.deduction_price) 订单押金
      this.setData({
        paid_price: Number(((Number(this.data.get_money) - Number(this.data.deduction_price) + Number(this.data.hy_money)).toFixed(2) - Number(this.data.user_happiness_integral) - Number(this.data.user_integral)).toFixed(2))
      })
    })
  },

  RenewWork() {

    this.get_paytype().then(() => {
      let paytype_list = this.data.paytype_list
      let itemList = []
      paytype_list.forEach((v, i) => {
        itemList.push(v.title)
      })

      wx.showActionSheet({
        itemList,
        success: (sheet) => {
          let tapIndex = sheet.tapIndex
          let paytype = paytype_list[tapIndex].paytype
          
          let wid = this.data.wid;
          if (paytype == 6) {
            wx.setStorageSync('pay_info', {
              a: 'wxapp2',
              do: 'RenewWork',
              uid: wx.getStorageSync('userInfo').id,
              work_id: wid,
              paytype
            })
            wx.navigateTo({
              url: '/online_bank/list?id=' + wid
            })
            return
          }
          getApp().globalData.post({
            data: {
              a: 'wxapp2',
              do: 'RenewWork',
              uid: wx.getStorageSync('userInfo').id,
              work_id: wid,
              paytype
            }
          }).then((res => {
            let data = res.data;
            if (data.pay_status == 2) {
              getApp().showModal(data.msg).then(() => {
                this.getWorkinfo()
                this.get_rechouse_list()
              })
              return
            }
            if (data.code == 0) {
              getApp().showModal(data.msg)
              return
            }
            if (getApp().globalData.appletpayves_info.work == 3) {
              getApp().payPlugin(data.orderNo).then(() => {
                getApp().showModal('支付成功').then(() => {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 this.getWorkinfo()
                  this.get_rechouse_list()
                })
              })
              return
            }

            if (data.jump) {
              this.selectComponent('#zfb_pay').get_code(data.jump)
              this.setData({
                show_code_img: true,
                has_jump: true,
                is_RenewWork: true,
              })
              return
            } else {
              this.setData({
                has_jump: false,
                is_RenewWork: false
              })
            }

            if (!data.package) {
              getApp().showModal('暂无法使用该支付方式，请选择其他支付方式', true).then(() => {
                this.RenewWork()
              })
              return
            }
            wx.requestPayment({
              nonceStr: data.nonceStr,
              package: data.package,
              paySign: data.paySign,
              timeStamp: data.timeStamp,
              signType: data.signType,
              complete: (s) => {
                if ("requestPayment:ok" == s.errMsg) {
                  wx.showToast({
                    title: "支付成功",
                    icon: 'none'
                  })
                  this.getWorkinfo()
                  this.get_rechouse_list()
                }
              }
            })
          }))

        }
      })
    })


  },

  to_baoxian() {
    wx.navigateTo({
      url: '/insurance/select_baoxian',
    })
  },

})